    {%- include "c_agile_slave/c_agile_slave_fun_common.jinja2" %}
    while (u8ILoop < len)
    {
        switch(address + u8ILoop)
        {
            {%- for region in table.regions.input_coils -%}
            {%- for register in region.registers %}
            case {{register.address}}: 
                {%- if register.length > 1 %}
                for (u8JLoop = 0; u8JLoop < {{register.length}} && u8ILoop < len; u8JLoop++, u8ILoop++)
                {
                    u8Bit = ptRegster->{{register.name}} & (1 << u8JLoop);
                    *(((uint8_t*)outbuf) + (u8ILoop / 8)) |= (u8Bit << (8 - u8ILoop % 8));
                }
                {%- else %}
                *(((uint8_t*)outbuf) + (u8ILoop / 8)) |= ptRegster->{{register.name}} << (8 - u8ILoop % 8);
                u8ILoop++;
                {%- endif %}
                break;
            {%- endfor %}
            {%- endfor %}
            default:
                return -1;
        }
    }

    return 0;